﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SystemDirectory.Common;
using SystemDirectory.Biz;
using SystemDirectory.Entity;
using SystemDirectory.Pages.Forms;

namespace SystemDirectory.Pages.Forms
{
    public partial class PrimiseAdmen : System.Web.UI.Page

    {
        
        public static bool IsCheck = false;
        public static Utilities.SearchType IsSearch;
        DataTable dtMinor;
        BOMinor buMinor;
        public static bool IsActiveTmp = false;
        private int lastPremiseId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                IsSearch = Utilities.SearchType.TypeAll;
                buMinor = new BOMinor();
                dtMinor = buMinor.Get(IsCheck, IsSearch);
                cbxInactive.Checked = IsActiveTmp;
                PagedDataSource pds = new PagedDataSource();
                DataView dv = new DataView(dtMinor);
                pds.DataSource = dv;
                pds.AllowPaging = true;
                pds.PageSize = 2;
                int NumPage = pds.PageCount;

                int CurrentPage;
                if (Request.QueryString["page"] != null)
                {
                    CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
                }
                else
                {
                    CurrentPage = 1;
                }

                pds.CurrentPageIndex = CurrentPage - 1;

                if (!pds.IsFirstPage)
                {
                    hplBackward.Visible = true;
                    hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
                }
                else
                {
                    hplBackward.Visible = false;
                }
                if (!pds.IsLastPage)
                {
                    hplForward.Visible = true;
                    hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
                }
                else
                {

                    hplForward.Visible = false;
                }

                rptMinor.DataSource = pds;
                rptMinor.DataBind();
                lblCurrent.Text = CurrentPage.ToString();
                lblTotal.Text = NumPage.ToString();
                BOPremise boPremise = new BOPremise();
                lastPremiseId=boPremise.GetLastId()+1;
                //LinkButton9.Attributes.Add("data-toggle", "modal");

                //-----------------------------------Modal---------------------------
                AddressBO bo = new AddressBO();
                DataTable dtAddress = bo.Get(postcode.Text, street.Text, town.Text);

                PagedDataSource pdsAdd = new PagedDataSource();
                DataView dvAdd = new DataView(dtAddress);
                pdsAdd.DataSource = dvAdd;
                pdsAdd.AllowPaging = true;
                pds.PageSize = 2;
                int NumPageAdd = pds.PageCount;

                int CurrentPageAdd;
                if (Request.QueryString["page"] != null)
                {
                    CurrentPageAdd = Convert.ToInt32(Request.QueryString["page"].ToString());
                }
                else
                {
                    CurrentPageAdd = 1;
                }

                pdsAdd.CurrentPageIndex = CurrentPage - 1;

                if (!pdsAdd.IsFirstPage)
                {
                    hplBackwardAdd.Visible = true;
                    hplBackwardAdd.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPageAdd - 1);
                }
                else
                {
                    hplBackwardAdd.Visible = false;
                }
                if (!pdsAdd.IsLastPage)
                {
                    hplForwardAdd.Visible = true;
                    hplForwardAdd.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPageAdd + 1);
                }
                else
                {
                    hplForwardAdd.Visible = false;
                }


                rptAddress.DataSource = pdsAdd;
                rptAddress.DataBind();
                lblCurrentAdd.Text = CurrentPageAdd.ToString();
                lblTotalAdd.Text = NumPageAdd.ToString();

                wrap.Visible = false;
            }


        }
        protected void cbxInactive_CheckedChanged(object sender, EventArgs e)
        {
            IsActiveTmp = cbxInactive.Checked;
            IsCheck = cbxInactive.Checked;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeAll;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.Type09;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }

        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeAE;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }

        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeFJ;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeKM;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton6_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeOR;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();

        }

        protected void LinkButton7_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeSV;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void LinkButton8_Click(object sender, EventArgs e)
        {
            IsSearch = Utilities.SearchType.TypeWZ;
            buMinor = new BOMinor();
            dtMinor = buMinor.Get(IsCheck, IsSearch);
            PagedDataSource pds = new PagedDataSource();
            DataView dv = new DataView(dtMinor);
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.PageSize = 2;
            int NumPage = pds.PageCount;

            int CurrentPage;
            if (Request.QueryString["page"] != null)
            {
                CurrentPage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                CurrentPage = 1;
            }

            pds.CurrentPageIndex = CurrentPage - 1;

            if (!pds.IsFirstPage)
            {
                hplBackward.Visible = true;
                hplBackward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage - 1);
            }
            else
            {
                hplBackward.Visible = false;
            }
            if (!pds.IsLastPage)
            {
                hplForward.Visible = true;
                hplForward.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(CurrentPage + 1);
            }
            else
            {

                hplForward.Visible = false;
            }

            rptMinor.DataSource = pds;
            rptMinor.DataBind();
            lblCurrent.Text = CurrentPage.ToString();
            lblTotal.Text = NumPage.ToString();
        }

        protected void savePremise_Click(object sender, EventArgs e)
        {
            Page.Validate("vgroup");
            
            if (Page.IsValid)
            {

                Premise premiseIn = new Premise();
                premiseIn.locationName = LocationName.Text;
                premiseIn.address1 = addressLine1.Text;
                premiseIn.postcode = postcode.Text;
                premiseIn.isActive = isActive.Checked;
                premiseIn.knowAs = KnowAs.Text;
                premiseIn.locationOrg = LocationOrganisation.Text;
                premiseIn.locationStatus = LocationStatus.Text;
                premiseIn.locationDate = statusDate.Text;
                premiseIn.address2 = addressLine2.Text;
                premiseIn.address3 = addressLine3.Text;
                premiseIn.ctyTown = citytown.Text;
                premiseIn.country = Country.Text;
                premiseIn.nationContry = NationCountry.Text;
                premiseIn.primary = primaryLocation.Checked;
                premiseIn.locationMa = locatinManaged.Checked;
                premiseIn.stNetCon = networkConnect.Checked;
                premiseIn.locatonDes = LocationDescription.Text;
                premiseIn.phoneNum = PhoneNumber.Text;
                premiseIn.faxNum = faxNumber.Text;
                premiseIn.minNum = miniNumber.Text;
                premiseIn.isShop = isShop.Checked;
                premiseIn.shopDate = shopDate.Text;
                premiseIn.specialistDhop = SpeciallistShop.Checked;
                premiseIn.mediaContact = mediaContact.Checked;
                premiseIn.mediaContactName = midiaConatcName.Text;
                premiseIn.localDemNote = LocalNotes.Text;
                premiseIn.cateringFac = CateringFac.Checked;
                premiseIn.cateringCon = cateringContact.Text;
                premiseIn.cateringType = CateringType.Text;
                premiseIn.isNet = isNetwok.Text;
                premiseIn.clientItfac = clientIt.Checked;
                premiseIn.clientItDe = clientItFac.Text;
                premiseIn.roomAvai = roomAvaibiaty.Checked;
                premiseIn.volunOpp = volunOpp.Checked;
                premiseIn.travelDatail = travelDetail.Text;
                premiseIn.travelNeaAil = TravelNearestAiport.Text;
                premiseIn.travalNeaRail = TravelNearestRail.Text;
                premiseIn.hostViset = HostVisits.Checked;
                premiseIn.hostContact = HostingContact.Text;
                premiseIn.visitOnsite = VisitorParkingOnsite.Checked;
                premiseIn.visitSpace = VisitorParkingSpaces.Text;
                premiseIn.visitAlte = VisitorParkingAltemative.Text;
                premiseIn.roomRate = RoomOnlyRate.Text;
                premiseIn.bbRate = BBRate.Text;
                premiseIn.dbbRate = DBBRate.Text;
                premiseIn.ddRate = DDRate.Text;
                premiseIn.hrRate = hrRate.Text;
                premiseIn.teaCof = TeaandCoffee.Text;
                premiseIn.luch = Lunch.Checked;
                premiseIn.noRoom = NoofMeetingRooms.Text;
                premiseIn.metRoom = MeetingRoomRate.Text;
                premiseIn.coding = coodding.Text;
                premiseIn.neRoom = NegotiatedRoom.Text;
                premiseIn.bbNeRoom = BBNegotiated.Text;
                premiseIn.dbbNeRoom = DBBNegotiated.Text;
                premiseIn.hrNeRoom = hrNegotiated.Text;
                premiseIn.lastNeRoom = "3/6/2013 12:00:00 AM";// LastNegotiated.Text;
                premiseIn.reNeOn = "3/6/2013 12:00:00 AM"; // RenegotiateOn.Text;
                premiseIn.preStatus = PrefrredStatus.Text;
                premiseIn.commen = Comments.Text;
                BOPremise boPremise = new BOPremise();
                boPremise.AddPremise(premiseIn);
                Response.Redirect("/Pages/Views/PremiseList.aspx");
            }
        }

        

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            //Page.Validate("vgroup");
            BOPremise boChe = new BOPremise();
            if (boChe.CheckName(args.Value))
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

        protected void lbnModal_Click(object sender, EventArgs e)
        {
            wrap.Visible = true;
        }
    }
}